home *** CD-ROM | disk | FTP | other *** search
- Path: info-server.bbn.com!news
- From: vanegas@jade.bbn.com (Rodrigo Vanegas)
- Newsgroups: comp.lang.c++
- Subject: Implementing a filtered iostream
- Date: 08 Mar 1996 15:27:11 -0500
- Organization: BBN
- Sender: vanegas@jade.bbn.com
- Message-ID: <kd4g2bjxrds.fsf@jade.bbn.com>
- Reply-To: vanegas@bbn.com
- NNTP-Posting-Host: jade.bbn.com
- X-Newsreader: Gnus v5.0.15
-
- How would I implement a subclass of iostream such that all data going
- through the IO would be filtered somehow. I imagine something like
- the following.
-
-
- class rot13stream : public fstream
- {
- // magic goes here!
- };
-
- main()
- {
- String m;
-
- fstream f;
- f.open("message");
- f << "Gur chapuyvar!" << endl;
- f.close();
-
- rot13stream r;
- r.open("message");
- m.getLine(r);
-
- cout << m;
- }
-
-
- sh$ run
- The punchline!
-
-
- Even better would be a way to implement a two-way string stream of
- sorts implementing a filter.
-
-
- class filterStream : public strstream // maybe?
- {
- // some magic.
- }
-
- class rot13filterStream : public filterStream
- {
- // more magic!
- }
-
- main()
- {
- String message;
-
- rot13filterStream filt;
- filt << "Gur vachg pbhyq pbzr va puhaxf" << endl;
- filt << "naq or eryrnfrq";
-
- message.getLine(filt);
- cout << "1: " << message << endl;
-
- filt << "va puhaxf nf jryy..." << endl;
- message = "";
- message.getLine(filt);
-
- cout << "2: " << message << endl;
- }
-
-
- sh$ run
- 1: The input could come in chunks
- 2: and be released in chunks as well...
-
-
- How about it? Can the standard C++ IO library handle this? I'd like
- to be able to take advantage of all those methods defined for
- iostream...
-
- --
- Rodrigo <Vanegas@bbn.com>
-